package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class Test4 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class,int.class);
        Object obj = c.newInstance("张三",18);
        Method[]methods = cls.getDeclaredMethods();
        for (Method method:methods){
            boolean mark = method.isAnnotationPresent(AutoRunMethod.class);
            if (mark){
                AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
                int value = arm.value();
                System.out.println("调用"+method.getName()+"方法"+value+"次");
                for (int i = 0;i<value;i++){//循环value次
                    method.invoke(obj);//调用方法
                }
            }else {
                System.out.println(method.getName()+"没有被标注");
            }
        }






    }
}
